﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel.Resources;

namespace Enough.Lifecycle.Helper
{
    public static class LocalizationHelper
    {
        private static ResourceLoader _resourceLoader;

        /// <summary>
        /// Translates the given resource
        /// </summary>
        /// <param name="resourceName">the name of the resource within Resources.rews</param>
        /// <param name="parameters">optional parameters for filling in {0}, {1}, etc</param>
        /// <returns>the translated resource, null if it is not known</returns>
        public static string Localize(string resourceName, params object[] parameters)
        {
            var resourceLoader = _resourceLoader;
            if (resourceLoader == null)
            {
                resourceLoader = new Windows.ApplicationModel.Resources.ResourceLoader();
                _resourceLoader = resourceLoader;
            }
            string translated = resourceLoader.GetString(resourceName);
            if (translated != null && parameters != null && parameters.Length > 0)
            {
                translated = string.Format(translated, parameters);
            }
            return translated;
        }
    }
}
